<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ProductReviews
 *
 * @author Eugin
 */
class FormProcessor_ProductReviews extends FormProcessor {
    
    public $page = null;
    
    public function __construct($db, $id = 0) {
        parent::__construct();
        $this->db = $db;
        $this->review = new DatabaseObject_ProductsReviews($this->db);
         if ($id!='0'){
        $this->review->load($id);
        $this->id = $this->review->getId();
        $this->productId = $this->review->productId;
        $this->userId = $this->review->userId;
        $this->author = $this->review->author;
        $this->text = $this->review->text;
        $this->rating = $this->review->rating;
        $this->status = $this->review->status;
        $this->date_added = $this->review->date_added;
        
        }
        
    }
    
      public function process(Zend_Controller_Request_Abstract $request) {
        // проверим название

        
        $this->text = trim($request->getPost('text'));
        $this->review->text = $this->text;
        
        $this->rating = trim($request->getPost('rating'));
        
        $this->review->rating = $this->rating;
        
        $this->review->productId = trim($request->getPost('productId'));
        
        if (Zend_Auth::getInstance()->getIdentity()->id)
        {
            $this->review->userId = Zend_Auth::getInstance()->getIdentity()->id;
            $this->review->author = Zend_Auth::getInstance()->getIdentity()->login;
        }
        else
        {
            $this->review->userId=0;
                $this->author = trim($request->getPost('author'));

              
                    $this->review->author = $this->author;
        }
        
        $this->review->date_added = date('Y-m-d H:i:s');
        $this->review->status = '1';
        $this->review->productId = trim($request->getPost('productId'));
        
          // если не было ошибок, сохраним jnpsd
        if (!$this->_validateOnly && !$this->hasError()) {
            $this->review->save();
        }
        
        return !$this->hasError();
      }
    
}